package com.supply.service.impl;

import com.supply.mapper.LeaveBillMapper;
import com.supply.pojo.LeaveBill;
import com.supply.pojo.LeaveBillExample;
import com.supply.service.LeaveBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LeaveBillServiceImpl implements LeaveBillService {
    @Autowired
    private LeaveBillMapper leaveBillMapper;

    @Override
    public List<LeaveBill> queryAll() {
        return leaveBillMapper.selectByExample(null);
    }

    @Override
    public List<LeaveBill> queryByUserId(Long id) {
        LeaveBillExample example = new LeaveBillExample();
        example.createCriteria().andUserIdEqualTo(id);
        return leaveBillMapper.selectByExample(example);
    }

    @Override
    public LeaveBill queryById(Long id) {

        return leaveBillMapper.selectByPrimaryKey(id);
    }

    @Override
    public int saveOrUpdate(LeaveBill leaveBill) {
        if (leaveBill.getId() == null){
            return leaveBillMapper.insert(leaveBill);
        }else{
            return leaveBillMapper.updateByPrimaryKey(leaveBill);
        }
    }

    @Override
    public int deleteById(Long id) {
        return leaveBillMapper.deleteByPrimaryKey(id);
    }
}
